<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<%@ page import="com.thinkgem.jeesite.common.utils.PropertiesLoader" %>
<html>
<head>
	<title>司机管理</title>
	<meta name="decorator" content="default"/>
	<script type="text/javascript" src="${ctxStatic}/jquery/ajaxfileupload.js"></script>
	<script type="text/javascript">
		$(document).ready(function(){
			//$("#name").focus();
			$("#inputForm").validate({
				submitHandler: function(form){
					loading('正在提交，请稍等...');
					form.submit();
				},
				errorContainer: "#messageBox",
				errorPlacement: function(error, element) {
					$("#messageBox").text("输入有误，请先更正。");
					if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
						error.appendTo(element.parent().parent());
					} else {
						error.insertAfter(element);
					}
				}
			});
			
			//验证司机的唯一性，通过手机号验证
		$("#driverTell").blur(function(){
		    var tell=$("#driverTell").val();
		    $.ajax({
		        url:"${ctx}/tb_driver/tbDriver/haverDriver?tell="+tell,
		        type:"post",
		        datatype:"",
		        success:function(data){
		        if(data!=null&&data!=""){
		        var peopletell=data.driverTell;
		        alert("电话号为："+peopletell+"的用户已被注册");
		        $("#driverTell").val("");
		        return false;
		        }
		    }
		    });
		});		
});
         
         /**
         *选中当前的checkbox显示对应的文件上传控件
         *
         */
         function inputUploadphoto(obj,e){
         	var $obj = $(obj);
       		if($obj.is(":checked")){      			
				$obj.parents().children("div").show();
			    $obj.parents().children("div").children("div").children("input").show();
			    //$obj.parents().children("div").children("div").show();
			}else{
				$("#isDriverLicense").val("0") ;
				$(".uploadphoto").css("display","none");
			}
			return;
         };
              
         function uploadimg(inputid,e,imgFile){
					 var imgid=$(inputid).parents().parents().children().eq(0).attr("id");
					 var hdiptid=$(inputid).parents().parents().parents().children(":input[type='hidden']").attr("id");
					 var uplpid=$(inputid).parents().parents().attr("class");
					 var faimgfile=$(inputid).parents().attr("id");
					 var DocumentType=$(inputid).parents().parents().parents().children(":input[type='checkbox']").attr("id");	
				            $.ajaxFileUpload({
				            url:"${ctx}/tb_driver/tbDriver/uploadImg?DocumentType="+DocumentType,
				            secureuri:false,  //是否启用安全提交,默认为false
				            fileElementId:imgFile,                  //文件选择框的id属性
				            async: false,
				            data: {
				            //加入的文本参数  
			                	"formFieldId" : "param1"
			           		 }, 
			           		dataType:"text", 
				            success:function(data){ 
				                //服务器响应成功时的处理函数
			                	data = data.replace("</pre>", '');
			                	data = data.replace("<PRE>", '');  //ajaxFileUpload会对服务器响应回来的text内容加上<pre>text</pre>前后缀
			                    data = data.replace("</PRE>", '');
			                    data = data.replace("<pre>", '');
			                    data = data.substring(data.indexOf("{"));
			                	var obj = JSON.parse(data);
			                	console.log(obj);
				               if(obj.flag != "1"){
				               		alert("图片上传失败");
				               	}else{
				               		var httpp="<%=PropertiesLoader.OSSPhotoUrlRequest()%>";
				               		var urs=httpp+obj.msg;
				               		var $obj = $(inputid);
				               		$obj.parents().children("img").attr("src",urs);
				               		//img标签的id并且此id获取该img标签后改变该标签的src属性
				               		$("#"+imgid).attr("src",urs);
				               		  		
				               		//将返回的上传路经赋给隐藏的input
				               		$("#"+hdiptid).val(urs);
				             
				               		//粉色的框框显示
				               		$("."+uplpid).css("display","block");
				               		
				               		//上传图片的input模块要影藏
				               		$("#"+imgFile).hide();
				               		$("#"+faimgfile).hide();
				               	   }
	                           },
	                                error: function(data,e) {
                                    alert(data.responseText);
                           },
                                 complete: function(XMLHttpRequest, textStatus) {
                                  this; // 调用本次AJAX请求时传递的options参数
                           }
	                   });
	                    return;	
	    };      
			      		
    </script>
	<style type="text/css">
		.driver_license{
			width:23%;
			float:left;
			
		}
		.driver_license>div>img{
			width: 300px;
			height: 170px;
		}
		.uploadphoto1,.uploadphoto2,.uploadphoto3,.uploadphoto4{
		    width:300px;
		    height:auto;
		    background-color: pink;
		    display: none;
		}
	</style>
</head>
<body>
	<ul class="nav nav-tabs">
		<li><a href="${ctx}/tb_driver/tbDriver/">司机列表</a></li>
		<li class="active"><a href="${ctx}/tb_driver/tbDriver/form?id=${tbDriver.id}">司机<shiro:hasPermission name="tb_driver:tbDriver:edit">${not empty tbDriver.id?'修改':'添加'}</shiro:hasPermission><shiro:lacksPermission name="tb_driver:tbDriver:edit">查看</shiro:lacksPermission></a></li>
	</ul><br/>
	<form:form id="inputForm" modelAttribute="tbDriver" action="${ctx}/tb_driver/tbDriver/save" method="post" class="form-horizontal">
		<form:hidden path="id"/>
		<form:hidden path="newPassword"/>
		<sys:message content="${message}"/>		
		<div class="control-group">
			<label class="control-label">真实姓名：</label>
			<div class="controls">
				<form:input path="driverName" htmlEscape="false" maxlength="50" class="input-xlarge required"/>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<%-- <div class="control-group">
			<label class="control-label">简称：</label>
			<div class="controls">
				<form:input path="driverShortName" htmlEscape="false" maxlength="20" class="input-xlarge "/>
			</div>
		</div> --%>
		<div class="control-group">
			<label class="control-label">身份证号码：</label>
			<div class="controls">
				<form:input path="driverIdCode" htmlEscape="false" maxlength="18" class="input-xlarge required"/>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<c:if test="${newPassword != null && newPassword != '' }">
			<div class="control-group">
			<label class="control-label">密码：</label>
			<div class="controls">
				<form:password path="newPassword" htmlEscape="false"  class="input-xlarge required"/>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		</c:if>
		
		<div class="control-group">
			<label class="control-label">电话：</label>
			<div class="controls">
				<form:input path="driverTell" htmlEscape="false" maxlength="11" class="input-xlarge required" />
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">拥有证件：</label>
			<div class="controls">
				<div class="driver_license">
					<input type="checkbox"  id = "_isQualificationCertificate" onclick="inputUploadphoto(this,event)"/>
					<label for="_isQualificationCertificate">从业资格证</label>
					<form:hidden path="isQualificationCertificate" id="isQualificationCertificate" />
					<div class="uploadphoto1">
	                    <img alt="请上传从业资格证" src="${ctxStatic}/images/bgi_103487.jpg"  id="showimg1" title="从业资格证">
		                <div id="inputUpload1">
		                		<label class="control-label">请上传您从业资格证照片：</label>         		
		                        <input id="imgFile1" name="myfile" type="file" onchange="uploadimg(this,event,'imgFile1')" />
		                </div>	
	               </div>
				</div>
				
				<div class="driver_license">
					<input type="checkbox"  id = "_isEscort" onclick="inputUploadphoto(this,event)"/>
					<label for="_isEscort">押运证</label>
					<form:hidden path="isEscort" id="isEscort" />
					<div class="uploadphoto2">
	                    <img alt="" src="${ctxStatic}/images/bgi_103487.jpg"  id="showimg2">
		                <div id="inputUpload2">
		                		<label class="control-label">请上传您的押运证照片：</label>         		
		                                                                        证&nbsp件&nbsp照&nbsp片<input id="imgFile2" name="myfile" type="file" onchange="uploadimg(this,event,'imgFile2')" />
		                </div>	
	                </div>
				</div>
				
				
				<div class="driver_license">
					<input type="checkbox"  id = "_isPosts" onclick="inputUploadphoto(this,event)"/>
					<label for="_isPosts">上岗证</label>
					<form:hidden path="isPosts" id="isPosts" />
					<div class="uploadphoto3">
	                    <img alt="" src="${ctxStatic}/images/bgi_103487.jpg"  id="showimg3">
		                <div id="inputUpload3">
		                		<label class="control-label">请上传您的上岗证照片：</label>         		
		                                                                       证&nbsp件&nbsp照&nbsp片<input id="imgFile3" name="myfile" type="file" onchange="uploadimg(this,event,'imgFile3')" />
		                </div>	
	               </div>
				</div>
				
				<div class="driver_license">
					<input type="checkbox"  id = "_isDriverLicense" onclick="inputUploadphoto(this,event)"/>
					<label for="_isDriverLicense">驾驶证</label>
					<form:hidden path="isDriverLicense" id="isDriverLicense"/>
					<div class="uploadphoto4">
	                    <img alt="" src="${ctxStatic}/images/bgi_103487.jpg"  id="showimg4">
		                <div id="inputUpload4">
		                		<label class="control-label">请上传您的驾驶证照片：</label>         		
		                                                                        证&nbsp件&nbsp照&nbsp片<input id="imgFile4" name="myfile" type="file" onchange="uploadimg(this,event,'imgFile4')" />
		                </div>	
	                </div>
				</div>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">备注：</label>
			<div class="controls">
				<form:textarea path="remarks" htmlEscape="false" rows="4" maxlength="150" class="input-xxlarge "/>
			</div>
		</div>
		<div class="form-actions">
			<shiro:hasPermission name="tb_driver:tbDriver:edit"><input id="btnSubmit" class="btn btn-primary" type="submit" value="保 存"/>&nbsp;</shiro:hasPermission>
			<input id="btnCancel" class="btn" type="button" value="返 回" onclick="history.go(-1)"/>
		</div>
	</form:form>
</body>
</html>